package com.cqust.junit;

import com.cqust.dao.CardDao;
import com.cqust.dao.RecordDao;
import com.cqust.dao.StudentDao;
import com.cqust.entity.Card;
import com.cqust.entity.Record;
import com.cqust.entity.Student;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyUnitTest2 {

    //简单的学生注册
    @Test
    public void insertStudent()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        StudentDao studentDao= (StudentDao) ac.getBean("studentDao");
        Student student=new Student();
        student.setSno("2020444229");
        student.setAge(22);
        student.setName("彭竹庚");
        student.setMajor("软件工程");
        if(studentDao.insert(student)>=0)
            System.out.println("学生注册成功！");
    }

    //简单的开卡
    @Test
    public void insertCard()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        CardDao cardDao= (CardDao) ac.getBean("cardDao");
        Card card=new Card();
        card.setSid(1);
        card.setName("彭竹庚");
        card.setCno("S001");
        card.setSno("2020444229");
        card.setBalance(1000);
        card.setLastUseTime("2022-10-26");
        if(cardDao.insert(card)>=0)
            System.out.println("开卡成功！");
    }

    //消费记录
    @Test
    public void insertConsum()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        RecordDao recordDao= (RecordDao) ac.getBean("recordDao");
        Record record=new Record();
        record.setCid(1);
        record.setConsumeTime("2022-10-26");
        record.setConsumeMoney(50);
        if(recordDao.insert(record)>=0)
            System.out.println("消费记录已更新！");
    }
}
